export default class orc_res extends Laya.Script {
    public static res_pkg:any = {};   

    public static prefabs_res = {};
    public static scene3D_res = {}; 
    
    sprite3D_res = {};
    public static now_num = 0;
    public static total_num = 10000;

    constructor() { super(); }
    
    //加载成功
    public static one_res_load_finished() {
        this.now_num ++;       
        orc.orc_data.memory_data.widget_scale = Laya.stage.height/1334;
        if (this.now_num >= this.total_num) {
            orc.event_manager.dispatch_event(orc.event_id.orc_res_event);
        }
    }

    //加载预制体
    public static load_prefab(url) {
        Laya.loader.load(url, Laya.Handler.create(this, function(json) {
            var pref = new Laya.Prefab();
            pref.json = json;
            this.prefabs_res[url] = pref;

            this.one_res_load_finished();
        }));
    }

    public static load_scene3D(url) {
        Laya.Scene3D.load(url, Laya.Handler.create(this, function(scene3d) {
            this.scene3D_res[url] = scene3d;

            this.one_res_load_finished();
        }));
    }

    //加载需要的资源
    public static preload_res_pkg() {
        orc.log("res_pkg:",this.res_pkg);
        orc.log("res_pkg:",this.res_pkg.prefabs);
        var i = 0;
        var url = "";
        this.total_num = 0;
        for(var key in this.res_pkg) {
            this.total_num += this.res_pkg[key].length;
        }

        this.now_num = 0;

        if (this.res_pkg.prefabs) {
            for(let i = 0; i < this.res_pkg.prefabs.length; i ++) {
                url = this.res_pkg.prefabs[i];
                this.load_prefab(url);
            }
        }

        if (this.res_pkg.scene3D) {
            for(let i = 0; i < this.res_pkg.scene3D.length; i ++) {
                url = this.res_pkg.scene3D[i];
                this.load_scene3D(url);
            }
        }

        // if (res_pkg.sprite3D) {
        //     for(let i = 0; i < res_pkg.sprite3D.length; i ++) {
        //         url = res_pkg.sprite3D[i];
        //         this.load_sprite3D(url);
        //     }
        // }
    }

    onEnable(): void {
    }

    onDisable(): void {
    }
}